employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    },
    # 更多员工数据
}

# 1. 新增员工信息
def add_employee(emp_id, name, age, gender, position, team, salary_history):
    employees[emp_id] = {
        "name": name,
        "age": age,
        "gender": gender,
        "position": position,
        "team": team,
        "salary_history": salary_history
    }

# 添加ID为102的新员工
add_employee(102, "Bob", 35, "Male", "Data Engineer", "Engineering", [75000, 85000])
print(employees)

# 2. 删除指定员工
def remove_employee(emp_id):
    if emp_id in employees:
        del employees[emp_id]
        return f"员工 {emp_id} 已删除"
    return f"员工 {emp_id} 不存在"

#删除ID为102的员工（如果存在）
remove_employee(102)
print(employees)

# 3. 更新员工101的年龄
if 101 in employees:
    employees[101]["age"] = 31
print(employees)

# 4. 增加员工101的最新薪资
if 101 in employees:
    employees[101]["salary_history"].append(95000)
print(employees)

# 5. 计算员工101的平均薪资
if 101 in employees:
    avg_salary = sum(employees[101]["salary_history"]) / len(employees[101]["salary_history"])
    print(f"员工101的平均薪资: {avg_salary:.2f}")

# 6. 找出所有年龄>25岁的员工姓名和ID
older_employees = {
    emp_id: emp["name"]
    for emp_id, emp in employees.items()
    if emp["age"] > 25
}
print("年龄大于25岁的员工:", older_employees)

# 7. 为每个员工添加bonus键（最新薪资的10%）
for emp_id in employees:
    if employees[emp_id]["salary_history"]:
        latest_salary = employees[emp_id]["salary_history"][-1]
        employees[emp_id]["bonus"] = latest_salary * 0.1
print(employees)

# 8. 更新员工101的职位
if 101 in employees:
    employees[101]["position"] = "Senior Data Scientist"
print(employees)

# 9. 从所有员工信息中移除gender键
for emp_id in employees:
    employees[emp_id].pop("gender", None)  # 使用None避免KeyError
print(employees)

# 10. 创建仅包含name和position的新字典
name_position_dict = {
    emp_id: {
        "name": emp["name"],
        "position": emp["position"]
    }
    for emp_id, emp in employees.items()
}
print(name_position_dict)
